package com.shiguiwu.springboot3.util;

import com.shiguiwu.springboot3.dto.AuthUser;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @description: 会员下上文
 * @author: stone
 * @date: Created by 2025/9/24 21:13
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.util
 */
public class MemberContextUtils {


    private MemberContextUtils() {

    }

    public static AuthUser getCurrentMember() {
        try {
            return (AuthUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        } catch (Exception e) {
            throw new RuntimeException("获取当前会员信息失败");
        }

    }


    public static Long getCurrentUserId() {
        return getCurrentMember().getId();
    }


    public static String getCurrentMemberName() {
        return getCurrentMember().getUsername();
    }


    public static String getCurrentMemberAvatar() {
        return getCurrentMember().getAvatarUrl();
    }

    public static String getCurrentMemberMobile() {
        return getCurrentMember().getMobile();
    }
}
